#include "PKB.h"

PKB::PKB(){
}

PKB::PKB(Parser* p){
	ast = (*p).getAST();
	varTable = (*p).getVarTable();
	procTable = (*p).getProcTable();
	constTable = (*p).getConstTable();;
	modifies = (*p).getModifies();
	uses = (*p).getUses();
	calls = (*p).getCalls();
	patternTable = (*p).getPatternTable();
	TotalLineNum = ast.getTotalLineNum();
	loopTable = (*p).getLoops();
	stmtLstTable = (*p).getStmtLstTable();
	plusTable = (*p).getPlus();
	minusTable = (*p).getMinus();
	timesTable = (*p).getTimes();
	contains = (*p).getContains();
	FollowsList = (*p).getFollows().getFollowsPair();
	FollowsMatrix = vector<vector<int>>(TotalLineNum+1, vector<int>(TotalLineNum+1,0));
	for(int i=0;i<FollowsList.size();i++)
		FollowsMatrix.at(FollowsList.at(i).first).at(FollowsList.at(i).second) = 1;
	ParentList = (*p).getParent().getParentPair();
	ParentMatrix = vector<vector<int>>(TotalLineNum+1, vector<int>(TotalLineNum+1,0));
	for(int i=0;i<ParentList.size();i++)
		ParentMatrix.at(ParentList.at(i).first).at(ParentList.at(i).second) = 1;

	fullUsesMatrix = vector<vector<int>>(TotalLineNum+1, vector<int>(varTable.getSize(),0));
}

AST PKB::getAST(){
	return ast;
}

VarTable PKB::getVarTable(){
	return varTable;
}

ProcTable PKB::getProcTable(){
	return procTable;
}

ConstTable PKB::getConstTable(){
	return constTable;
}

Modifies PKB::getModifies(){
	return modifies;
}

Uses PKB::getUses(){
	return uses;
}

Calls PKB::getCalls(){
	return calls;
}

PatternTable PKB::getPatternTable(){
	return patternTable;
}

StmtLstTable PKB::getStmtLstTable() {
	return stmtLstTable;
}

PlusTable PKB::getPlusTable() {
	return plusTable;
}

MinusTable PKB::getMinusTable() {
	return minusTable;
}

TimesTable PKB::getTimesTable() {
	return timesTable;
}

Contains PKB::getContains() {
	return contains;
}

int PKB::getTotalLineNum(){
	return TotalLineNum;
}


// Follows
vector<pair<int, int>> PKB::getFollowsList(){
	return FollowsList;
}

vector<vector<int>> PKB::getFollowsMatrix(){
	return FollowsMatrix;
}


// Parent
vector<pair<int, int>> PKB::getParentList(){
	return ParentList;
}

vector<vector<int>> PKB::getParentMatrix(){
	return ParentMatrix;
}


// Follows*
void PKB::setFollowsStarList(vector<pair<int, int>> list){
	FollowsStarList = list;
}

vector<pair<int, int>> PKB::getFollowsStarList(){
	return FollowsStarList;
}

void PKB::setFollowsStarMatrix(vector<vector<int>> matrix){
	FollowsStarMatrix = matrix;
}

vector<vector<int>> PKB::getFollowsStarMatrix(){
	return FollowsStarMatrix;
}


// Parent*
void PKB::setParentStarList(vector<pair<int, int>> list){
	ParentStarList = list;
}

vector<pair<int, int>> PKB::getParentStarList(){
	return ParentStarList;
}

void PKB::setParentStarMatrix(vector<vector<int>> matrix){
	ParentStarMatrix = matrix;
}

vector<vector<int>> PKB::getParentStarMatrix(){
	return ParentStarMatrix;
}


LoopTable PKB::getLoops(){
	return loopTable;
}

// Modifies
void PKB::setFullModifiesTable(vector<pair<int,int>> fmt){
	fullModifiesTable = fmt;
}
vector<pair<int,int>> PKB::getFullModifiesTable(){
	return fullModifiesTable;
}

void PKB::setFullModifiesMap(vector<int> map){
	fullModifiesMap = map;
}
vector<int> PKB::getFullModifiesMap(){
	return fullModifiesMap;
}

// Uses
void PKB::setFullUsesTable(vector<pair<int,int>> fut){
	fullUsesTable = fut;
}
vector<pair<int,int>> PKB::getFullUsesTable(){
	return fullUsesTable;
}

void PKB::setFullUsesMatrix(vector<vector<int>> matrix){
	fullUsesMatrix = matrix;
}
vector<vector<int>> PKB::getFullUsesMatrix(){
	return fullUsesMatrix;
}

// Procedure Modifies
void PKB::setPModifiesTableV1(vector<vector<int>> pmtv1){
	PModifiesTableV1 = pmtv1;
}
vector<vector<int>> PKB::getPModifiesTableV1(){
	return PModifiesTableV1;
}

void PKB::setPModifiesTableV2(vector<pair<int,int>> pmtv2){
	PModifiesTableV2 = pmtv2;
}
vector<pair<int,int>> PKB::getPModifiesTableV2(){
	return PModifiesTableV2;
}

// Procedure Uses
void PKB::setPUsesTableV1(vector<vector<int>> putv1){
	PUsesTableV1 = putv1;
}
vector<vector<int>> PKB::getPUsesTableV1(){
	return PUsesTableV1;
}

void PKB::setPUsesTableV2(vector<pair<int,int>> putv2){
	PUsesTableV2 = putv2;
}
vector<pair<int,int>> PKB::getPUsesTableV2(){
	return PUsesTableV2;
}

// Next
void PKB::setNext(Next n){
	next = n;
}

Next PKB::getNext(){
	return next;
}

vector<pair<int, int>> PKB::getNextList(){
	NextList = next.getNextPair();
	return NextList;
}

void PKB::setNextMatrix(vector<vector<int>> nMatrix){
	NextMatrix = nMatrix;
}

vector<vector<int>> PKB::getNextMatrix(){
	return NextMatrix;
}

// Next*
void PKB::setNextStarList(vector<pair<int,int>> list){
	NextStarList = list;
}

vector<pair<int,int>> PKB::getNextStarList(){
	return NextStarList;
}

void PKB::setNextStarMatrix(vector<vector<int>> matrix){
	NextStarMatrix = matrix;
}

vector<vector<int>> PKB::getNextStarMatrix(){
	return NextStarMatrix;
}

// Next Bip
void PKB::setNextBip(NextBip n) {
	nextBip = n;
}

NextBip PKB::getNextBip() {
	return nextBip;
}

void PKB::setProcTable(ProcTable p) {
	procTable = p;
}

vector<pair<int,int>> PKB::getNextBipList(){
	return nextBip.getNextBipPair();
}

void PKB::setNextBipMatrix(vector<vector<int>> matrix){
	NextBipMatrix = matrix;
}

vector<vector<int>> PKB::getNextBipMatrix(){
	return NextBipMatrix;
}

// NextBip*
void PKB::setNextBipStarList(vector<pair<int,int>> list) {
	NextBipStarList = list;
}

vector<pair<int,int>> PKB::getNextBipStarList(){
	return NextBipStarList;
}

void PKB::setNextBipStarMatrix(vector<vector<int>> matrix){
	NextBipStarMatrix = matrix;
}

vector<vector<int>> PKB::getNextBipStarMatrix(){
	return NextBipStarMatrix;
}

// Call
vector<pair<int,int>> PKB::getCallsList(){
	vector<pair<int,int>> list;
	vector<Triple> callsTable = calls.getCalls();
	for(int i=0;i<calls.getCallSize();i++)
		list.push_back(pair<int,int>(callsTable.at(i).getSecond(),callsTable.at(i).getThird()));
	return list;
}

vector<int> PKB::getCalleeList(){
	vector<Triple> callTable = calls.getCalls();
	vector<int> calleeList;
	for(int i=0;i<callTable.size();i++)
		calleeList.push_back(callTable.at(i).getThird());
	sort(calleeList.begin(), calleeList.end());
	calleeList.erase(unique(calleeList.begin(), calleeList.end() ), calleeList.end());
	return calleeList;
}

// Call*
void PKB::setCallsStarList(vector<pair<int,int>> list){
	CallsStarList = list;
}

vector<pair<int,int>> PKB::getCallsStarList(){
	return CallsStarList;
}

// Statement Table
void PKB::setStmtTable(StmtTable st){
	sTable = st;
}

StmtTable PKB::getStmtTable(){
	return sTable;
}

//Affect Bip
void  PKB::setAffectBipSimpleText(vector<vector<int>> textList,vector<int> rootOfList){
	extendProcedure = textList;
	extendRoot=rootOfList;
}
vector<vector<int>>  PKB::getExtendProcedure(){
	return extendProcedure;
}
vector<int>  PKB::getExtendRoot(){
	vector<int> er;
	for(int i=0;i<extendRoot.size();i++)
		if(extendRoot.at(i) == 1)
			er.push_back(i);
	return er;
}

// Affects
void PKB::setAffectsList(vector<pair<int,int>> list){
	AffectsList = list;
}

void PKB::setAffectsMatrix(vector<vector<int>> matrix){
	AffectsMatrix = matrix;
}

vector<pair<int,int>> PKB::getAffectsList(){
	return AffectsList;
}

vector<vector<int>> PKB::getAffectsMatrix(){
	return AffectsMatrix;
}

// Affects*
void PKB::setAffectsStarList(vector<pair<int,int>> list){
	AffectsStarList = list;
}

void PKB::setAffectsStarMatrix(vector<vector<int>> matrix){
	AffectsStarMatrix = matrix;
}

vector<pair<int,int>> PKB::getAffectsStarList(){
	return AffectsStarList;
}

vector<vector<int>> PKB::getAffectsStarMatrix(){
	return AffectsStarMatrix;
}

void PKB::setContains(Contains c) {
	contains = c;
}

void  PKB::setSortedCall(vector<int> t){
        sortedCall = t;
}
vector<int>  PKB::getSortedCall(){
        return sortedCall;
}